## -*- Makefile -*-
##
## User: Luca Piccinelli
## Time: Feb 13, 2011 12:35:55 PM

# Define the target directories.
CONF = Debug

BUILD_ROOT = build
DIST_ROOT  = dist

BUILD_DIR := $(BUILD_ROOT)/$(CONF)
DIST_DIR  := $(DIST_ROOT)/$(CONF)

SRC_DIR = ../../src
COMMON     = $(SRC_DIR)/common
FACTORY    = $(SRC_DIR)/factory
FORMATTERS = $(SRC_DIR)/formatters
GENERATORS = $(SRC_DIR)/generators
PIPELINE   = $(SRC_DIR)/pipeline

INCLUDE_DIR = ../../include
INCLUDE_COMMON     = $(INCLUDE_DIR)/common
INCLUDE_FACTORY    = $(INCLUDE_DIR)/factory
INCLUDE_FORMATTERS = $(INCLUDE_DIR)/formatters
INCLUDE_GENERATORS = $(INCLUDE_DIR)/generators
INCLUDE_PIPELINE   = $(INCLUDE_DIR)/pipeline

SUBDIRS = $(COMMON) $(FACTORY) $(FORMATTERS) $(GENERATORS) $(PIPELINE)

PY_VERSION = 3.1

#### Compiler and tool definitions shared by all build targets #####
CP = cp
CC = g++
RM = rm -f
ifeq ($(CONF),Debug)
	BASICOPTS = -g
else
	BASICOPTS =
endif
CPPFLAGS = $(BASICOPTS) -ansi
DEPFLAGS = -MMD -MP -MF
INCLUDE = -I$(INCLUDE_DIR) -I/usr/include/python$(PY_VERSION) -I/usr/include/qt4
LIB_PATH = -L../../dist/$(CONF)/GNU-Linux-x86
COMPILE  = $(CC) -c $(CPPFLAGS) $(INCLUDE) -fPIC
BUILD  = $(CC) $(CPPFLAGS)

SRCS =	\
	pipeit_wrap.cpp \

OBJS  = $(addprefix $(BUILD_DIR)/, $(patsubst %.cpp, %.o, $(notdir $(SRCS))))

DEPFILES := $(wildcard $(addsuffix .d, $(OBJS)))

USERLIBS = -lpipeit
LIBS     = $(USERLIBS)

all: _pipeit.so

%_wrap.cpp: %.i
	mkdir -p $(DIST_DIR)
	swig -Wall -c++ -python -py3 -o $@ -outdir $(DIST_DIR) $<

SHAREDLIB_FLAGS = -shared 
_pipeit.so: $(OBJS)
	mkdir -p $(DIST_DIR)
	$(BUILD) -o $(DIST_DIR)/$@ $(OBJS) $(LIB_PATH) $(SHAREDLIB_FLAGS) $(LIBS)

# Compile source files into .o files
SRCS_FILTER  = $(filter %$*.cpp, $(SRCS))

$(BUILD_DIR)/%.o: $(SRCS_FILTER)
	mkdir -p $(BUILD_DIR)
	$(RM) $@.d
	$(COMPILE) $(DEPFLAGS) $@.d $(SRCS_FILTER) -o $@

.PHONY: clean install all
	

#### Clean target deletes all generated files ####
clean:
	$(RM) -r $(BUILD_ROOT)
	$(RM) -r $(DIST_ROOT)
	$(RM) *.py *.cpp
	
install:
	$(CP) $(DIST_DIR)/pipeit.py /usr/lib/python$(PY_VERSION)/dist-packages
	$(CP) $(DIST_DIR)/_pipeit.so /usr/lib/python$(PY_VERSION)/dist-packages



-include $(DEPFILES)